package com.servlet.users;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dao.UsersDAO;
import com.entity.Users;

public class AddUserServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String userName = request.getParameter("user_name");
		String userPassword = request.getParameter("user_password");

		Users users = new Users(userName, userPassword);
		users.setUser_password(userPassword);
		UsersDAO usersDAO = new UsersDAO();
		if (usersDAO.save(users)) {
			request.getRequestDispatcher("/servlet/FindAllUsersServlet").forward(
					request, response);
  
		}

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String userName = request.getParameter("user_name");
		String userPassword = request.getParameter("user_password");

		Users users = new Users(userName, userPassword);
		users.setUser_password(userPassword);
		UsersDAO usersDAO = new UsersDAO();
		if (usersDAO.save(users)) {
			request.getRequestDispatcher("/servlet/FindAllUsersServlet").forward(
					request, response);
  
		}
		
	}

}
